package nowcoder.fallibility;

/**
 * @author Cheng Jun
 * Description: https://www.nowcoder.com/test/question/done?tid=61649094&qid=112849#summary
 *
 * finally一定会在return之前执行，但是如果finally使用了return或者throw语句，将会使trycatch中的return或者throw失效
 * @version 1.0
 * @date 2022/9/19 13:51
 */
public class TryCatchFinally {
    public static void main(String[] args) {
        // double d = 5.4e12;
        System.out.println("Ceil d1="+Math.ceil(-0.5));
        // NumberFormatException.forInputString
        // System.out.println(Integer.parseInt("123a"));
        int[] a = null; a[0] = 1;
        System.out.println(42 == 42.0f);
        System.out.println(getNumber(0));
        System.out.println(getNumber(1));
        System.out.println(getNumber(2));
        System.out.println(getNumber(4));
    }

    public static int getNumber(int num) {
        try {
            int result = 2 / num;
            return result;
        } catch (Exception exception) {
            return 0;
        } finally {
            if (num == 0) {
                return -1;
            }
            if (num == 1) {
                return 1;
            }
        }
    }
}
